function clear(){
  var  endLi=document.getElementsByClassName('style3');
  for (var i =0 ;i<endLi.length; i++){
     endLi[i].className ='bk'
  }
  return endLi;
}

function skill(lead,oul,ws,parent){
    var x = 0;
    var y = 0;
    var num = 0;
    oul.onmousemove = function (event){  //获取坐标
          x = event.pageX;
          y = event.pageY;
    };
     window.onkeydown = function(event){
             if(event.keyCode == 81){
                  //技能执行
                  num++;
                 GeneratingSkills(x,y,lead,oul,ws,num,parent);
             }
     }
}

function GeneratingSkills(x,y,lead,oul,ws,num,parent) {

    //发出生成子弹响应
    var data = {
        action:'Gskill',
        class:'Index',
        content:{
            user:ws.userId,type:'skill',name:ws.userId + 'skill'+num
        }
    };
    data = JSON.stringify(data);
    ws.ws.send(data);

    var zidan = document.createElement('div');

    zidan.className = 'skill '+ws.userId +'skill' + num;
    zidan.style.position='absolute'
    zidan.style.height=30 + 'px';
    zidan.style.width=30 + 'px';
    zidan.style.left = lead.offsetLeft +'px';
    zidan.style.top = lead.offsetTop +'px';
    zidan.innerHTML = '<img src="img/0.png">'
    oul.appendChild(zidan);

    //获取游戏中的实际坐标
      y =  y - (zidan.offsetHeight / 2);

    if(lead.offsetLeft >= oul.offsetWidth - parent.offsetWidth){
        x = x + (oul.offsetWidth - parent.offsetWidth) - (zidan.offsetWidth / 2);
        console.log('-1')
      }  else if(lead.offsetLeft - 150 > 0) {
        x = x + (lead.offsetLeft - 150) - (zidan.offsetWidth / 2);
        console.log('-2')
    } else {
          x = x  - (zidan.offsetWidth / 2);
      }
      var GameX = x - oul.offsetLeft;
      var GameY = y - oul.offsetTop;

    //利用勾股定理算出sin值cos值

   var disX = GameX - lead.offsetLeft;
   var disY = GameY - lead.offsetTop;

   var r = Math.sqrt((disX*disX) + (disY*disY));

   var cos = disX / r;
   var sin = disY / r;


   killImplement(sin,cos,zidan,lead,ws,num)

}

function killImplement(sin,cos,zidan,lead,ws,count){

    var num = 0;
    var set = 0;
     //获取子弹触发时 人物位置
    var currentLeft  =  lead.offsetLeft;
    var currentTop =   lead.offsetTop;

    var kill = function(){
           set += cos * 2;

           var stop =window.requestAnimationFrame(kill)   //这里应当发送子弹实时坐标位置


           // zidan.style.left =   currentLeft +    (cos * num) + 'px';
           // zidan.style.top  =  currentTop   +    (sin * num) +'px';

           var left = currentLeft +    (cos * num);
           var top = currentTop   +    (sin * num)

        var data = {
            action:'Gskill',
            class:'Index',
            content:{
                user:ws.userId,type:'Cskill',name:ws.userId + 'skill'+count,top:top,left:left,
            }
        };

        data = JSON.stringify(data);
        ws.ws.send(data);

           num += 4;
           if(num > 800){
               window.cancelAnimationFrame(stop);
           }
    }
    kill();




}

export {
   clear as clear,
    skill as skill
}